<p>Just as you can’t cut something into three halves, you can’t grab a <code>substring</code> that starts or ends outside the original
<code>String</code>'s bounds, you can’t use <code>substring</code> to get a reversed portion of a <code>String</code>, and you can’t get the
<code>charAt</code> a value that’s before the <code>String</code> starts or after it ends.</p>
<p>This rule detects when negative literal or <code>String::length</code> is passed as an argument to the <code>String::substring</code>,
<code>String::charAt</code> and related methods.</p>
<h2>Noncompliant Code Example</h2>
<pre>
String speech = "Now is the time for all good people to come to the aid of their country.";

String substr1 = speech.substring(-1, speech.length());  // Noncompliant; start and end values both bad
String substr2 = speech.substring(speech.length(), 0); // Noncompliant, start value must be &lt; end value
char ch = speech.charAt(speech.length());  // Noncompliant
</pre>
<h2>Compliant Solution</h2>
<pre>
String speech = "Now is the time for all good people to come to the aid of their country.";

String substr1 = speech; // Closest correct values to original code yield whole string
String substr2 = new StringBuilder(speech).reverse().toString()
char ch = speech.charAt(speech.length()-1);
</pre>

